<template>
    <IDrawer v-model="defaultValue" :loading="loading" :width="400">
        <Form :model="data" :rules="ruleValidate" ref="formCreate" label-position="top">
            <FormItem label="公司名称" prop="name">
                <Input v-model="data.name"></Input>
            </FormItem>
            <FormItem label="公司简称" prop="short_name">
                <Input v-model="data.short_name"></Input>
            </FormItem>
            <FormItem label="担保企业" prop="assure">
                <Select v-model="data.assure">
                    <Option :value="0">账册企业</Option>
                    <Option :value="1">电商企业</Option>
                    <Option :value="2">物流企业</Option>
                </Select>
            </FormItem>
            <FormItem label="营业执照" prop="license">
                <UploadImage v-model="data.license" url="upload"></UploadImage>
            </FormItem>
            <FormItem label="备注" prop="remark">
                <Input v-model="data.remark" type="textarea" :rows="4"></Input>
            </FormItem>
        </Form>
        <div slot="footer">
            <Button type="primary" icon="ios-add" @click="submit('formCreate')">提交</Button>
            <Button type="warning" icon="md-log-out" @click="defaultValue = false">返回</Button>
        </div>
    </IDrawer>
</template>

<script>
    import IDrawerMixins from "../../../../mixins/iDrawerMixins";
    import IDrawer from "../../../../components/layout/IDrawer";
    import UploadImage from "../../../../components/form/uploadImage";
    import IData from './data'

    export default {
        name: "update",
        components: {UploadImage, IDrawer},
        mixins: [IDrawerMixins, IData],
        mounted(){
            this.getData();
        },
        methods: {
            getData(){
                this.loading = true;
                this.$http.get(`customer/index/${this.props.id}/edit`).then((res) => {
                    this.data = res;
                }).finally(() => {
                    this.loading = false;
                });
            },
            submit(name){
                this.validate(name).then(() => {
                    this.loading = true;
                    this.$http.put(`customer/index/${this.props.id}`,
                        Object.assign({}, this.data)
                    ).then(() => {
                        this.defaultValue = false;
                    }).finally(() => {
                        this.loading = false;
                    });
                }).catch(() => {
                });
            }
        }
    }
</script>

<style scoped>

</style>
